package cn.com.victorysoft.ylgl.service.commons.mybatis.paging.dialect.support;

import cn.com.victorysoft.ylgl.service.commons.mybatis.paging.dialect.AbstractDialect;

/***
 * @author gechaoqing
 */
public class HSQLDialect
        extends AbstractDialect {
    @Override
    public boolean supportsLimit() {
        return true;
    }

    @Override
    public String getLimitString(String sql, int offset, int limit) {
        return getLimitString(sql, offset, Integer.toString(offset), Integer.toString(limit));
    }

    private String getLimitString(String sql, int offset, String offsetPlaceholder, String limitPlaceholder) {
        boolean hasOffset = offset > 0;

        return new StringBuffer(sql.length() + 10).append(sql).insert(sql.toLowerCase().indexOf("select") + 6, " top " + limitPlaceholder).toString();
    }
}
